1 /** 2 Run-time options. 3 */ 4 module unit_threaded.options; 5 6 /// 7 struct Options { 8 bool multiThreaded; 9 string[] testsToRun; 10 bool debugOutput; 11 bool list; 12 bool exit; 13 bool forceEscCodes; 14 bool random; 15 uint seed; 16 bool stackTraces; 17 bool showChrono; 18 } 19 20 /** 21 * Parses the command-line args and returns Options 22 */ 23 auto getOptions(string[] args) { 24 25 import std.stdio : writeln; 26 import std.random : unpredictableSeed; 27 import std.getopt : getopt; 28 29 bool single; 30 bool debugOutput; 31 bool help; 32 bool list; 33 bool forceEscCodes; 34 bool random; 35 uint seed = unpredictableSeed; 36 bool stackTraces; 37 bool showChrono; 38 39 getopt(args, "single|s", &single, //single-threaded 40 "debug|d", &debugOutput, //print debug output 41 "esccodes|e", 42 &forceEscCodes, "help|h", &help, "list|l", &list, "random|r", &random, 43 "seed", &seed, "trace|t", &stackTraces, "chrono|c", &showChrono,); 44 45 if (help) { 46 writeln("Usage: <progname> <options> <tests>...\n", "Options: \n", 47 " -h/--help: help\n", " -s/--single: single-threaded\n", 48 " -l/--list: list tests\n", " -d/--debug: enable debug output\n", 49 " -e/--esccodes: force ANSI escape codes even for !isatty\n", 50 " -r/--random: run tests in random order\n", 51 " --seed: set the seed for the random order\n", 52 " -t/--trace: enable stack traces\n", 53 " -c/--chrono: print execution time per test",); 54 } 55 56 if (random) { 57 if (!single) 58 writeln("-r implies -s, running in a single thread\n"); 59 single = true; 60 } 61 62 version (unitUnthreaded) 63 single = true; 64 65 immutable exit = help || list; 66 return Options(!single, args[1 .. $], debugOutput, list, exit, 67 forceEscCodes, random, seed, stackTraces, showChrono); 68 }